package com.shakespace.artofandroid.chapter02

import android.os.Parcel
import android.os.Parcelable

// 2020-01-08 NOTE:  the path of book ,must same as Book.aidl , or get "couldn't find import..."
// ref : https://www.jianshu.com/p/47441bdc3509

data class Book(val bookId: Int, val bookName: String) : Parcelable {
    constructor(parcel: Parcel) : this(
        parcel.readInt(),
        parcel.readString()!!
    )

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeInt(bookId)
        parcel.writeString(bookName)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object CREATOR : Parcelable.Creator<Book> {
        override fun createFromParcel(parcel: Parcel): Book {
            return Book(parcel)
        }

        override fun newArray(size: Int): Array<Book?> {
            return arrayOfNulls(size)
        }
    }
}